package com.achieve.mqtt.service.impl;

import com.achieve.mqtt.domain.TbLampStatus;
import com.achieve.mqtt.mapper.TbLampStatusMapper;
import com.achieve.mqtt.service.TbLampStatusService;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @author z6001
 * @description 针对表【tb_lamp_status】的数据库操作Service实现
 * @createDate 2025-04-20 17:15:03
 */
@Service
public class TbLampStatusServiceImpl extends ServiceImpl<TbLampStatusMapper, TbLampStatus>
        implements TbLampStatusService {

    @Override
    public void saveDeviceStatus(String payload) {
        Map<String, Object> map = JSON.parseObject(payload, Map.class);
        String deviceId = map.get("deviceId").toString();
        Integer status = Integer.parseInt(map.get("status").toString());
        TbLampStatus tbLampStatus = new TbLampStatus();
        tbLampStatus.setDeviceid(deviceId);
        tbLampStatus.setStatus(status);
        tbLampStatus.setCreatetime(new Date());
        tbLampStatus.setUpdatetime(new Date());
        super.save(tbLampStatus);

    }
}




